package com.tpix;

import java.io.IOException;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

public class DetailsServlet extends HttpServlet implements Servlet {
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		//get the information from the request
		String action = request.getParameter("action");
		String kind = (String) request.getSession().getAttribute("kind");
		String idString = (String) request.getSession().getAttribute("idString");
		long id = Long.parseLong(idString.trim());
		Key key = KeyFactory.createKey(kind, id);

		// get reference to core object
		PixieCore core = (PixieCore)request.getSession().getAttribute("core");
		if (core == null) {
			core = new PixieCore();
			request.getSession().setAttribute("core", core);
		}
		
		if (action.equals("Delete")) {
			core.deletePhoto(key);
		}
		else if (action.equals("Main Page")) {
			// do nothing
		}
		response.sendRedirect("/home.jsp");
		
		
		
		
	

	}

}
